package org.sxf.app.sign.fragment;

import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.lidroid.xutils.util.LogUtils;

import org.sxf.app.sign.R;
import org.sxf.app.sign.widgt.LoadingDialog;

/**
 * Created by zqc on 17/1/17.
 */
public class BaseFragment extends Fragment {

    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    private String mParam1;
    private String mParam2;

//    public Context mContext;

    public static BaseFragment newInstance(String param1, String param2) {
        BaseFragment fragment = new BaseFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    public BaseFragment() {
        // Required empty public constructor
    }

    public boolean onPhysicalKeyPressed(int keyCode){
        LogUtils.d("onPhysicalKeyPressed");
        return false;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        TextView textView = new TextView(getActivity());
        textView.setText(R.string.app_name);
        return textView;
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
    }

    @Override
    public void onDetach() {
        super.onDetach();
    }

    protected LoadingDialog _loadingDialog = null;

    protected void popLoadingDialog(String msgStr){
        dismissLoadingDialog();
        _loadingDialog = new LoadingDialog(getActivity(), msgStr);
        _loadingDialog.startLoadingDialog();
    }

    protected void dismissLoadingDialog(){
        if (_loadingDialog != null){
            _loadingDialog.stopLoadingDialog();
        }
    }
}
